import React, { useEffect, useState, useRef } from 'react';
import { Modal, Space, Button, Tabs, Form, Row, Col, Input, Select, Checkbox } from 'dw-mx';
import { useSewTask } from 'dw-mx-sew';
import { Code } from 'dw-mx-extend';
import { request } from 'dw-mx-request';

export default function AUTUTC(props) {
    const [form] = Form.useForm();
    // 流程任务
    const sewTask = useSewTask();

    const [initValues, setInitValues] = useState(null);

    // 流程驱动事件监听
    const doExecuteMethodDescribInBPMN = async () => {
        return true;
    };

    const chk_preGoPrevious = async () => {
        return true;
    };

    const configCU = async () => {
        return true;
    };

    const configDDS = async () => {
        return true;
    };

    const configGlobal = async () => {
        return true;
    };

    const configMachine = async () => {
        return true;
    };

    const goAbort = async () => {
        return true;
    };

    const goNext = async () => {
        return true;
    };

    const processVars = sewTask.getProcessVars();

    const initForm = async () => {
        const result = await request('/mx/SEWEngine/refreshStatus', { tid: processVars.getTid() });
        setInitValues({
            autexetime: result.autexetime,
            proceduredone: result.proceduredone,
            reporttext: result.reporttext,
        });
    };

    const redoAUT = async () => {
        const result = await request('/mx/SEWEngine/redoAUT', { tid: processVars.getTid() });
        setInitValues({
            autexetime: result.autexetime,
            proceduredone: result.proceduredone,
            reporttext: result.reporttext,
        });
    };

    //注册事件
    sewTask.registerEventListeners({
        doExecuteMethodDescribInBPMN,
        chk_preGoPrevious,
        configCU,
        configDDS,
        configGlobal,
        configMachine,
        goAbort,
        goNext,
    });

    useEffect(() => {
        initForm();
    }, []);

    const callback = async () => {};

    // UI
    const layout = {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 },
    };

    const tailLayout = {
        wrapperCol: { offset: 6, span: 18 },
    };

    return initValues ? (
        <>
            <Form form={form} {...layout} layout={'horizontal'} initialValues={initValues}>
                <Row>
                    <Col span={24}>
                        <Form.Item label="执行时间" name="autexetime">
                            <Input maxLength={10} readOnly={true} disabled={true} />
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={24}>
                        <Form.Item label="执行情况" name="proceduredone">
                            <Select options={Code.STRINGCODE('0:执行失败,1:执行成功,2:出现异常,3:尚未执行,4:正在执行')} disabled={true} />
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={24}>
                        <Form.Item label="执行情况描述" name="reporttext">
                            <Input.TextArea maxLength={10} readOnly={true} disabled={true} />
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={24}>
                        <Form.Item {...tailLayout}>
                            点击
                            <Button onClick={redoAUT} type="link">
                                下一步
                            </Button>
                            ，重新执行此操作。
                        </Form.Item>
                        <Form.Item {...tailLayout}>如有问题，请联系系统管理员或现场系统运维人员。</Form.Item>
                    </Col>
                </Row>
                {/*<Row>*/}
                {/*    <Col span={24}>*/}
                {/*        <Form.Item name="tname">*/}
                {/*            <div style="padding-left: 183px; color: #6A6A6A;">*/}
                {/*                <li style="font-size: 14px ">*/}
                {/*                    <span style="color: 3C3C3C">执行情况为异常，不允许返回上一步。</span>*/}
                {/*                </li>*/}
                {/*            </div>*/}
                {/*        </Form.Item>*/}
                {/*    </Col>*/}
                {/*</Row>*/}
            </Form>
        </>
    ) : (
        <div>Loading.....</div>
    );
}
